<?php

namespace app\data\controller\api;

use GuzzleHttp\Client;
use think\admin\Controller;

/**
 * 地图接口
 * Class Map
 * @package app\data\controller\api
 */
class Map extends Controller
{

    /**
     * 腾讯地图逆地址解析
     * @return void
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function tencentGeoCoder()
    {
        $data = $this->_vali([
            'long.require' => '经度不能为空！',
            'lat.require' => '纬度不能为空！',
        ]);
        $latitude = $data['lat'];
        $longitude = $data['long'];

        $url = 'https://apis.map.qq.com/ws/geocoder/v1/?key=OJNBZ-GNNC2-RHPUP-CIYYA-3IHKH-XWBEC&location=' . "{$latitude},{$longitude}";

        $client = new Client();
        $response = $client->request('GET', $url);
        $response = $response->getBody();
        $response = json_decode($response, true);

        $this->success('地址解析成功', $response);
    }
}